package com.atguigu.interpreter;

import java.util.HashMap;

/**
 * @program: design-patterns
 * @author: yangshen
 * @description: 变量的解释器
 * @create: 2022-03-13 13:16
 **/
public class VarExpression extends Expression {
    /**
     * key=a, key=b, key=c
     */
    private final String key;

    public VarExpression(String key) {
        this.key = key;
    }

    /**
     * 根据变量的名称返回对应的值
     * @param var hashMap {a=10, b=20}
     * @return hashMap中key对应的值
     */
    @Override
    public int interpreter(HashMap<String, Integer> var) {
        return var.get(key);
    }
}
